﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Movizard.Model;

namespace Movizard
{
    public partial class frmMain : Form
    {
        MovieCollection collection = new MovieCollection();

        public frmMain()
        {
            InitializeComponent();
            collection.CollectionChanged += collection_CollectionChanged;
            movieCollectionItemBindingSource.DataSource = collection;
        }

        void collection_CollectionChanged(object sender, EventArgs e)
        {
            grdMovies.Refresh();
        }

        private void mnuAddFolder_Click(object sender, EventArgs e)
        {
            if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                collection.AddFolder(folderBrowser.SelectedPath);
                movieCollectionItemBindingSource.ResetBindings(false);
                collection.QueryMovies();
            }
        }

        private void mnuAbout_Click(object sender, EventArgs e)
        {
            FrmAbout about = new FrmAbout();
            about.ShowDialog();
        }

        private void grdMovies_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > 0)
            {
                MovieCollectionItem item = grdMovies.Rows[e.RowIndex].DataBoundItem as MovieCollectionItem;
                switch (grdMovies.Columns[e.ColumnIndex].DataPropertyName)
                {
                    case "Directory":
                        Process.Start("explorer.exe", item.Directory.FullName);
                        break;
                    case "Movie":
                        Process.Start(item.Movie.ImdbURL);
                        break;
                }
            }
        }

        private void mnuRenameFolders_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in grdMovies.SelectedRows)
            {
                ((MovieCollectionItem)row.DataBoundItem).RenameFolder();
            }
        }
    }
}
